import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';
import React, {useState, useEffect} from 'react';
import DeviceInfo from 'react-native-device-info';
import {Colors} from 'react-native/Libraries/NewAppScreen';

function App() {
  const isDarkMode = useColorScheme() === 'dark';
  const [deviceInfo, setDeviceInfo] = useState({
    BundleId: '',
    Version: '',
    ReadableVersion: '',
    BuildNumber: '',
    Tablet: false,
    ApplicationName: '',
    Brand: '',
    Model: '',
    DeviceType: '',
    DeviceNameSync: '',
  });

  useEffect(() => {
    const fetchDeviceInfo = async () => {
      const BundleId = await DeviceInfo.getBundleId();
      const Version = await DeviceInfo.getVersion();
      const ReadableVersion = await DeviceInfo.getReadableVersion();
      const BuildNumber = await DeviceInfo.getBuildNumber();
      const Tablet = await DeviceInfo.isTablet();
      const ApplicationName = await DeviceInfo.getApplicationName();
      const Brand = await DeviceInfo.getBrand();
      const Model = await DeviceInfo.getModel();
      const DeviceType = await DeviceInfo.getDeviceType();
      const DeviceNameSync = await DeviceInfo.getDeviceNameSync();

      setDeviceInfo({
        BundleId,
        Version,
        ReadableVersion,
        BuildNumber,
        Tablet,
        ApplicationName,
        Brand,
        Model,
        DeviceType,
        DeviceNameSync,
      });
    };

    fetchDeviceInfo();
  }, []);

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <View
          style={{
            backgroundColor: isDarkMode ? Colors.black : Colors.white,
            padding: 16,
          }}>
          <Text style={styles.sectionTitle}>Device Information</Text>
          <Text style={styles.infoText}>BundleId: {deviceInfo.BundleId}</Text>
          <Text style={styles.infoText}>Version: {deviceInfo.Version}</Text>
          <Text style={styles.infoText}>
            ReadableVersion: {deviceInfo.ReadableVersion}
          </Text>
          <Text style={styles.infoText}>
            BuildNumber: {deviceInfo.BuildNumber}
          </Text>
          <Text style={styles.infoText}>
            Tablet: {deviceInfo.Tablet ? 'Yes' : 'No'}
          </Text>
          <Text style={styles.infoText}>
            ApplicationName: {deviceInfo.ApplicationName}
          </Text>
          <Text style={styles.infoText}>Brand: {deviceInfo.Brand}</Text>
          <Text style={styles.infoText}>Model: {deviceInfo.Model}</Text>
          <Text style={styles.infoText}>
            DeviceType: {deviceInfo.DeviceType}
          </Text>
          <Text style={styles.infoText}>
            DeviceNameSync: {deviceInfo.DeviceNameSync}
          </Text>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  sectionTitle: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 16,
  },
  infoText: {
    fontSize: 16,
    marginBottom: 8,
  },
});

export default App;
